package com.ethanzzh.security.core.ethanzzhdemo.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;
import java.util.Date;

//过滤器 filter 可以拿到原始的http请求和相应的信息
//但是拿不到真正处理方法的信息
//@Component
public class TimeFilter implements Filter {



    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("time filter init");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        System.out.println("time filter start");
        Long start = new Date().getTime();
        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("耗时: "+ (new Date().getTime() - start));
        System.out.println("time filter finish");

    }

    @Override
    public void destroy() {

        System.out.println("time filter destroy");
    }
}
